const db = require("../../lib/db");
 
//新建文章点赞
exports.addPraise = (value) => {
    let _sql = `INSERT INTO praise set ?`;
    return db.queryWithPool(_sql, value);
  };
  
  //获取文章点赞量、判断是否点赞
  exports.getPraiseCount = (articleId, userId) => {
    let _sql;
    let params = [];
    
    if (userId == -1) {
      _sql = `SELECT count(*) AS count FROM praise WHERE article_id = ?`;
      params = [articleId];
    } else {
      _sql = `SELECT count(*) AS count FROM praise WHERE user_id = ? and article_id = ?`;
      params = [userId, articleId];
    }
    return db.queryWithPool(_sql, params);
  };
  